package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.RevolveSessionJOBBean;
import com.ymatou.iapi.csim.service.RevolveSessionJOBCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_queuesessionWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
/**
*会话转接(JOB)
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RevolveSessionJOB{
	private static RevolveSessionJOBCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csIdA=Integer.parseInt(TestDataManager.getRandomNum(5));
	private Integer csIdB=Integer.parseInt(TestDataManager.getRandomNum(5));
	private Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	private static ymt_queuesessionWapper queuesessionWapper=new ymt_queuesessionWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("会话转接(JOB)");
	}

	@Before
	public void caseUp() {
		call=new RevolveSessionJOBCall();
		queuesessionWapper.deleteAll();
		onlinecsWapper.deleteBy(MapUtil.hashMap("CSId",csIdA,"Status",0));
		onlinecsWapper.deleteBy(MapUtil.hashMap("CSId",userId,"Status",0));
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RevolveSessionJOB_1() {
		Logger.start(true,"会话转接(JOB)");
		try {
			//csIdA上线
			ymt_onlinecs onlinecs=service.getOnlineCS(csIdA);
			//csIdA 主动会话
			ymt_cssession csSession=service.getOpenSession(csIdA,userId);
			csIdA=csSession.getCSId();//这里给csidA赋值 目的为了，当前的用户已经在会话中，直接把当前的csId赋值给csIdA
			//csIdA 更新为离线
		//	onlinecs.setStatus(1);
			onlinecsWapper.updateByPrimaryKey(onlinecs);
			//call.setData(bean);
			call.callService();	
			//csIdA 关闭会话
			onlinecs=onlinecsWapper.selectBy(MapUtil.hashMap("CSId",csIdA)).get(0);
			Logger.verifyEquals(1, onlinecs.getStatus(), "验证csIdA 关闭会话");
			//csIdA 添加会话队列
			int count=queuesessionWapper.selectBy_Count(MapUtil.hashMap("CSId",csSession.getUserId()));
			Logger.verifyEquals(0, count, "验证csIdA 添加会话队列");
			//csIdA 删除会话
			int count2=onlinecsWapper.selectBy_Count(MapUtil.hashMap("CSId",csIdA,"Status",0));
			Logger.verifyEquals(0, count2, "验证csIdA 删除会话");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}